clear all
tempfile tempsave
set seed ${seed}

do "${scripts}_output.do"
do "${scripts}_sumstat.do"
do "${scripts}_textab.do"

/*Macros*/
local data 			"National Longitudinal Study of Adolescent to Adult Health"
local source 		"Own calculations."
local signif 		"Significance levels: * \(p<0.10\), ** \(p<0.05\), *** \(p<0.01\)."
local error 		"Standard errors (in parentheses) are clustered at the school level."
local standard  	"All right-hand side variables are standardized on the estimation sample ($\mu=0$, $\sigma=1$)."
local controls 		"\emph{Child Controls}:" ///
					"Firstborn dummy, linear birth cohort trend (in months) by gender," ///
					"20 principal components of the full matrix of genetic data." ///
					"\emph{Family Controls}:" ///
					"Age of mother at birth, years of education of both mother and father," ///
					"average potential wages of both mother and father," ///
					"the standard deviation of potential wages of both mother and father, dummies for non-US born mothers and fathers," ///
					"a dummy for Christian religion, state fixed effects."
local controlfct	"\emph{Control Function}: Share white, share single mothers, maternal education (average),"  ///
					"share females, share migrants. All control function variables are calculated"  ///
					"as leave-cohort-out school averages."
local controlfct2	"\emph{Control Function}: Share white, share single mothers, maternal education (average),"  ///
					"share females, share migrants."
local notesize scriptsize

// -----------------------------------------------------
// Table 1
// -----------------------------------------------------
local groups t o c
local t eduyears hs coll2y coll4y postgrad
local o f_over1 teach_master teach_5years teach_new class
local c pgs_edu gender firstborn age_home_w1 agemum rel edumother edufather bornus_mother bornus_father bartik_mean_mother bartik_mean_father

use aid HsId `t' `o' `c' sample1 w0 if sample1==1 using "${data}data_estim.dta", clear
qui: gstats transform (standardize)	pgs_edu f_over1  [aw=w0] , replace

gdistinct HsId
local N="`: di string(r(N),"%9.0fc")'"
local NS="`: di string(r(ndistinct),"%9.0fc")'"

la var eduyears "Years of Education"
la var hs "High School Degree"
la var coll2y "2-year College Degree"
la var coll4y "4-year College Degree"
la var postgrad "Post-Graduate Degree"
la var pgs_edu "\PGS"
la var f_over1 "\IQuali"
la var class "Class Size"
la var teach_5years "Experienced Teacher (\%)"
la var teach_new "New Teacher (\%)"
la var teach_master "Teacher w/ MA (\%)"
la var gender "Female"
la var firstborn "Firstborn"
la var age_home_w1 "Age in Months (Wave 1)"
la var edumother "Education Mother (in Years)"
la var edufather "Education Father (in Years)"
la var bornus_mother "Foreign-born Mother"
la var bornus_father "Foreign-born Father"
la var bartik_mean_mother "Potential Wage/Hour Mother"
la var bartik_mean_father "Potential Wage/Hour Father"
la var agemum "Maternal Age at Birth"
la var rel "Christian"


foreach g of local groups{
	gstats tabstat ``g'', s(count mean sd min max) prettystats matasave
	mata: `g' = (GstatsOutput.getOutputGroup(1))
	mata: st_matrix("`g'", `g')
	matname `g' ``g'', rows(.)
	xsvmat  `g', names(col) rowlabels(v1) idstr("`g'") nidstr(group) saving("${temp}sum_`g'", replace) rename(c1 count`s' c2 mean`s' c3 sd`s' c4 min`s' c5 max`s')
}
clear
foreach g of local groups{
	 append using "${temp}sum_`g'.dta"
}
replace mean=mean+0.000001

/*Construct Table*/
local name tab1

#delimit;
sumstat v1 mean sd min max, name(${tablepath}`name') replace
flush_l(v1) flush_c(mean sd min max) format_2(mean sd min max)
headlabel("~" "Mean" "SD" "Min" "Max")
grouplabel("Educational~Attainment" "Child~and~Family~Characteristics" "School~Quality~Indicators")
head2label("~" "\thead{N=`N'};~\thead{High~Schools=`NS'}")
first(v1) long(no) landscape(no) width(1) grouping(yes) grouporder(t c o) head2(1 4);
#delimit cr

#delimit;
sumstat v1 mean sd min max, name(${tablepath}`name') replace
flush_l(v1) flush_c(mean sd min max) format_2(mean sd min max)
headlabel("~" "Mean" "SD" "Min" "Max")
grouplabel("Educational~Attainment" "Child~and~Family~Characteristics" "School~Quality~Indicators")
head2label("~" "\thead{N=`N'};~\thead{High~Schools=`NS'}")
first(v1) long(no) landscape(no) width(1) grouping(yes) grouporder(t c o) head2(1 4);
#delimit cr

local title "Summary Statistics"
local desc 	"This table shows summary statistics for the core analysis sample." ///
			"The sample is restricted to genotyped individuals who (i) are of European descent," ///
			"and (ii) attended an Add Health high school or an associated feeder school in wave 1." ///
			"Observations with missing information in any of the displayed variables" ///
			"are dropped by list-wise deletion."
#delimit;
textab,	title(`title') name(`name') replace width(1) file(tex) notesize(`notesize')
		note_paper("`source' `desc'") data(`data')
        inpath(${tablepath}) path_paper(${paper_tables});
#delimit cr

// -----------------------------------------------------
// Table 2
// -----------------------------------------------------
use "${data}data_estim.dta", replace
local name tab2

/*Get Estimates*/
local models ///
t2_1 t2_2 t2_3 t2_4
local coefs ///
pgs_edu f_over1
output `models', clist(`coefs') replay

foreach m in t2_2 t2_4{
	estimates use "${results}`m'"
	local d_b_`m' ="`: di string(e(d_b),"%9.3f")'"
	local d_se_`m'="`: di string(e(d_se),"%9.3f")'"
	local d_lb_`m'="`: di string(e(d_lb),"%9.3f")'"
	local d_ub_`m'="`: di string(e(d_ub),"%9.3f")'"
	if e(d_p)<=0.1{
		local star_`m' "\sym{*}"
	}
	if e(d_p)<=0.05{
		local  star_`m' "\sym{**}"
	}
	if e(d_p)<=0.01{
		local  star_`m' "\sym{***}"
	}
	if e(d_p)>0.1{
		local star_`m' "\sym{~}"
	}
}

/*Set up Table*/
cap texdoc init "${tablepath}`name'.tex", replace force
#delimit;
tex \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi};
tex \begin{tabular*}{1\linewidth}{@{\hskip\tabcolsep\extracolsep\fill}l*{4}{c}};
tex \toprule;
tex	\multicolumn{1}{c}{~}&
	\multicolumn{2}{c}{\thead{{Years of Education:}\\{Between- vs. Within-Family}}}&
	\multicolumn{2}{c}{\thead{{Predicted Years of Education:}\\{w/o vs. w/ Control Function}}}\\;
tex \cmidrule(lr){2-3}\cmidrule(lr){4-5};
tex \thead{{~}\\{~}}&
	\thead{{~}\\{(1)}}&
	\thead{{~}\\{(2)}}&
	\thead{{~}\\{(3)}}&
	\thead{{~}\\{(4)}}\\;
tex \midrule;
tex \thead[l]{\PGS}						&${c_1_1}&${c_2_1}&${c_3_1}&${c_4_1}\\;
tex \thead[l]{\IQuali}					&${c_1_2}&${c_2_2}&${c_3_2}&${c_4_2}\\;
tex \midrule;
tex \thead[l]{Difference in coefficients}	&\multicolumn{2}{c}{\thead[c]{{`d_b_t2_2'`star_t2_2'}\\{(`d_se_t2_2')}\\{[`d_lb_t2_2', `d_ub_t2_2']}}}
											&\multicolumn{2}{c}{\thead[c]{{`d_b_t2_4'`star_t2_4'}\\{(`d_se_t2_4')}\\{[`d_lb_t2_4', `d_ub_t2_4']}}}\\;
tex \midrule;
tex \thead[l]{Child Controls}			&\ye&\ye&\no&\no\\;
tex \thead[l]{Family Controls}			&\ye&\ye&\no&\no\\;
tex \thead[l]{Control Function}			&\ye&\ye&\no&\ye\\;
tex \thead[l]{Sibling Fixed Effect}		&\no&\ye&\no&\no\\;
tex \thead[l]{N}						&$ob_1&$ob_2&$ob_3&$ob_4\\;
tex \thead[l]{$\text{R}^2$}				&$rs_1&$rs_2&$rs_3&$rs_4\\;
tex \thead[l]{Outcome Mean}				&$mu_1&$mu_2&$mu_3&$mu_4\\;
tex \thead[l]{Outcome SD}				&$sd_1&$sd_2&$sd_3&$sd_4\\;
tex \bottomrule;
tex \end{tabular*};
#delimit cr
texdoc close

local title "Testing for Genetic Nurture and Selection into Schools"
local desc  "This table shows the associations of \PGS and \IQuali" ///
			"with years of education (left panel) and predicted years of education (right panel)." ///
			"The left panel shows estimates in the sibling sample:" ///
			"Column (1) displays results from a between-family comparison." ///
			"Column (2) displays results from a within-family comparison." ///
			"The right panel shows estimates in the core analysis sample:" ///
			"Column (3) displays results without any controls." ///
			"Column (4) displays results including the control function variables." ///
			"Predicted education is calculated from a regression of" ///
			"completed years of education on all \emph{Child Controls} and \emph{Family Controls}." ///
			"We test for the equality of coefficients in columns (1) and (2) as well as (3) and (4), respectively." ///
			"Next to point estimates, we present standard errors (in parentheses), and 95\% confidence intervals (in brackets)."

#delimit;
textab, title(`title') name(`name') replace
width(1.3) file(tex) notesize(`notesize')
note_paper("`source' `desc' `controls' `controlfct' `standard' `signif' `error'")
data(`data')
inpath(${tablepath}) path_paper(${paper_tables});
#delimit cr


// -----------------------------------------------------
// Table 3
// -----------------------------------------------------
use "${data}data_estim.dta", replace
local name tab3

/*Get Estimates*/
local models t3_1 t3_2 t3_3 t3_4 t3_5 t3_6
local coefs pgs_edu ///
f_over1 c.pgs_edu#c.f_over1  ///
teach_master c.pgs_edu#c.teach_master  ///
teach_5years c.pgs_edu#c.teach_5years  ///
teach_new c.pgs_edu#c.teach_new  ///
class c.pgs_edu#c.class  ///
f_over2 c.pgs_edu#c.f_over2
output `models', clist(`coefs') replay

/*Set up Table*/
texdoc init "${tablepath}`name'.tex", replace force
#delimit;
tex \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi};
tex \begin{tabular*}{1\linewidth}{@{\hskip\tabcolsep\extracolsep\fill}l*{6}{c}};
tex \toprule;
tex \multicolumn{1}{c}{\textbf{~}}&
	\multicolumn{2}{c}{\thead[c]{Overall}}&
	\multicolumn{4}{c}{\thead[c]{Decomposition of \IQuali}}\\;
tex \cmidrule(lr){2-3}\cmidrule(lr){4-7};
tex \thead[l]{{Outcome:}\\{Years of Education}}
			 &\thead{{PCA}\\{(1)}}
			 &\thead{{\citet{Anderson2008}}\\{(2)}}
			 &\thead{{~}\\{(3)}}
			 &\thead{{~}\\{(4)}}
			 &\thead{{~}\\{(5)}}
			 &\thead{{~}\\{(6)}}\\;
tex \midrule;
tex \thead[l]{\PGS}						  &${c_1_1}&${c_2_1}  &${c_3_1} &${c_4_1} &${c_5_1} &${c_6_1} \\;
tex \thead[l]{\IQuali}					  &${c_1_2}&${c_2_12} &${c_3_2} &${c_4_2} &${c_5_2} &${c_6_2} \\;
tex \thead[l]{\PGS $\times$ \IQuali}	  &${c_1_3}&${c_2_13} &${c_3_3} &${c_4_3} &${c_5_3} &${c_6_3} \\;
tex \thead[l]{Teacher w/ MA}		      &${c_1_4}&${c_2_4}  &${c_3_4} &${c_4_4} &${c_5_4} &${c_6_4} \\;
tex \thead[l]{\PGS $\times$ Teacher w/ MA}&${c_1_5}&${c_2_5}  &${c_3_5} &${c_4_5} &${c_5_5} &${c_6_5} \\;
tex \thead[l]{Exp. Teacher}			  	  &${c_1_6}&${c_2_6}  &${c_3_6} &${c_4_6} &${c_5_6} &${c_6_6} \\;
tex \thead[l]{\PGS $\times$ Exp. Teacher} &${c_1_7}&${c_2_7}  &${c_3_7} &${c_4_7} &${c_5_7} &${c_6_7} \\;
tex \thead[l]{New Teacher}				  &${c_1_8}&${c_2_8}  &${c_3_8} &${c_4_8} &${c_5_8} &${c_6_8} \\;
tex \thead[l]{\PGS $\times$ New Teacher}  &${c_1_9}&${c_2_9}  &${c_3_9} &${c_4_9} &${c_5_9} &${c_6_9} \\;
tex \thead[l]{Class Size}			 	  &${c_1_10}&${c_2_10}&${c_3_10}&${c_4_10}&${c_5_10}&${c_6_10}\\;
tex \thead[l]{\PGS $\times$ Class Size}   &${c_1_11}&${c_2_11}&${c_3_11}&${c_4_11}&${c_5_11}&${c_6_11}\\;
tex \midrule;
tex \thead[l]{Child Controls}			&\ye&\ye&\ye&\ye&\ye&\ye\\;
tex \thead[l]{Family Controls}			&\ye&\ye&\ye&\ye&\ye&\ye\\;
tex \thead[l]{Control Function}			&\ye&\ye&\ye&\ye&\ye&\ye\\;
tex \thead[l]{N}						&$ob_1&$ob_2&$ob_3&$ob_4&$ob_5&$ob_6\\;
tex \thead[l]{$\text{R}^2$}				&$rs_1&$rs_2&$rs_3&$rs_4&$rs_5&$rs_6\\;
tex \thead[l]{Outcome Mean}				&$mu_1&$mu_2&$mu_3&$mu_4&$mu_5&$mu_6\\;
tex \thead[l]{Outcome SD}				&$sd_1&$sd_2&$sd_3&$sd_4&$sd_5&$sd_6\\;
tex \bottomrule;
tex \end{tabular*};
#delimit cr
texdoc close

local title "Association of Years of Education with \PGS and School Environments"
local desc  "This table shows the joint association of \PGS and \IQuali" ///
			"with completed years of education."
#delimit;
textab, title(`title') name(`name') replace
width(1.3) file(tex) notesize(`notesize')
note_paper("`source' `desc' `controls' `controlfct' `standard' `signif' `error'")
data(`data')
inpath(${tablepath}) path_paper(${paper_tables});
#delimit cr

// -----------------------------------------------------
// Table 4
// -----------------------------------------------------
use "${data}data_estim.dta", replace
local name tab4

/*Get Estimates*/
local models t3_1 t5_1 t5_2 t5_3 t5_4 t5_5
local coefs pgs_edu f_over1    	///
c.pgs_edu#c.f_over1  			///
pvt_lag_res c.pvt_lag_res#c.f_over1  	///
grade_sci_res c.grade_sci_res#c.f_over1 ///
grade_mat_res c.grade_mat_res#c.f_over1
output `models', clist(`coefs') replay

/*Set up Table*/
texdoc init "${tablepath}`name'.tex", replace force
#delimit;
tex \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi};
tex \begin{tabular*}{1\linewidth}{@{\hskip\tabcolsep\extracolsep\fill}l*{6}{c}};
tex \toprule;
tex \multicolumn{1}{c}{\textbf{~}}&
	\multicolumn{1}{c}{\thead[c]{Baseline}}&
	\multicolumn{1}{c}{\thead[c]{{Interacted}\\{controls}}}&
	\multicolumn{1}{c}{\thead[c]{{Non-}\\{linearities}}}&
	\multicolumn{3}{c}{\thead[c]{{Subsample w/}\\{lagged ability measures}}}\\;
tex \cmidrule(lr){2-2}\cmidrule(lr){3-3}\cmidrule(lr){4-4}\cmidrule(lr){5-7};
tex \thead[l]{{Outcome:}\\{Years of Education}}
			 &\thead{{(1)}}
			 &\thead{{(2)}}
			 &\thead{{(3)}}
			 &\thead{{(4)}}
			 &\thead{{(5)}}
			 &\thead{{(6)}}\\;
tex \midrule;
tex \thead[l]{\PGS}						  		&${c_1_1}&${c_2_1}  &${c_3_1} &${c_4_1}&${c_5_1}&${c_6_1} \\;
tex \thead[l]{\IQuali}					  		&${c_1_2}&${c_2_2}  &${c_3_2} &${c_4_2}&${c_5_2}&${c_6_2} \\;
tex \thead[l]{\PGS $\times$ \IQuali}	  		&${c_1_3}&${c_2_3}  &${c_3_3} &${c_4_3}&${c_5_3}&${c_6_3} \\;
tex \thead[l]{PVT}		      					&${c_1_4}&${c_2_4}  &${c_3_4} &${c_4_4}&${c_5_4}&${c_6_4} \\;
tex \thead[l]{PVT $\times$ \IQuali}				&${c_1_5}&${c_2_5}  &${c_3_5} &${c_4_5}&${c_5_5}&${c_6_5} \\;
tex \thead[l]{GPA Science}			  	  		&${c_1_6}&${c_2_6}  &${c_3_6} &${c_4_6}&${c_5_6}&${c_6_6} \\;
tex \thead[l]{GPA Science $\times$ \IQuali} 	&${c_1_7}&${c_2_7}  &${c_3_7} &${c_4_7}&${c_5_7}&${c_6_7} \\;
tex \thead[l]{GPA Math}				  			&${c_1_8}&${c_2_8}  &${c_3_8} &${c_4_8}&${c_5_8}&${c_6_8} \\;
tex \thead[l]{GPA Math $\times$ \IQuali}  		&${c_1_9}&${c_2_9}  &${c_3_9} &${c_4_9}&${c_5_9}&${c_6_9} \\;
tex \midrule;
tex \thead[l]{Child Controls}														&\ye&\ye&\ye&\ye&\ye&\ye\\;
tex \thead[l]{Family Controls}														&\ye&\ye&\ye&\ye&\ye&\ye\\;
tex \thead[l]{Control Function}														&\ye&\ye&\ye&\ye&\ye&\ye\\;
tex \thead[l]{All interactions (\IQuali\negspace, \PGS\negspace, $\mathbf{X}_i(a)$)}&\no&\ye&\no&\no&\no&\no\\;
tex \thead[l]{$2^{nd}$ Polynomial (\IQuali\negspace, \PGS\negspace)}				&\no&\no&\ye&\no&\no&\no\\;
tex \thead[l]{N}																	&$ob_1&$ob_2&$ob_3&$ob_4&$ob_5&$ob_6\\;
tex \thead[l]{$\text{R}^2$}															&$rs_1&$rs_2&$rs_3&$rs_4&$rs_5&$rs_6\\;
tex \thead[l]{Outcome Mean}															&$mu_1&$mu_2&$mu_3&$mu_4&$mu_5&$mu_6\\;
tex \thead[l]{Outcome SD}															&$sd_1&$sd_2&$sd_3&$sd_4&$sd_5&$sd_6\\;
tex \bottomrule;
tex \end{tabular*};
#delimit cr
texdoc close

local title "Association of Years of Education with \PGS and School Environments"
local desc  "This table shows the joint association of \PGS and \IQuali" ///
			"with completed years of education." ///
			"In column (2), we control for all possible interactions between \PGS\negspace," ///
			"\IQuali\negspace, \emph{Child Controls}, \emph{Family Controls}, and the \emph{Control Function}." ///
			"In column (3), we control for second-order polynomials of \PGS and \IQuali" ///
			"and allow for all possible interactions of both indicators." ///
			"In column (4), we replicate our baseline specification on a sample of students for which we observe" ///
			"ability measures before they enter high school." ///
			"In column (5) and (6), we control for lagged ability measures and their interaction with \IQuali\negspace." ///
			"All lagged ability measures are residualized by regressing them on \PGS\negspace, \emph{Child Controls}, \emph{Family Controls}," ///
			" and the \emph{Control Function}."
			
#delimit;
textab, title(`title') name(`name') replace ///
width(1.3) file(tex) notesize(`notesize') ///
note_paper("`source' `desc' `controls' `controlfct' `standard' `signif' `error'") ///
data(`data') ///
inpath(${tablepath}) path_paper(${paper_tables});
#delimit cr


// -----------------------------------------------------
// Table 5
// -----------------------------------------------------
use "${data}data_estim.dta", replace
local name tab5

/*Get Estimates*/
local models t3_1 t4_1 t4_2 t4_3 t4_4 t4_5 t4_6 t4_7
local coefs pgs_edu ///
f_over1 c.pgs_edu#c.f_over1  ///
RobSchlOther c.pgs_edu#c.RobSchlOther

output `models', clist(`coefs') replay

/*Set up Table*/
texdoc init "${tablepath}`name'.tex", replace force
#delimit;
tex \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi};
tex \begin{tabular*}{1\linewidth}{@{\hskip\tabcolsep\extracolsep\fill}l*{8}{c}};
tex \toprule;
tex \multicolumn{1}{c}{~}&
	\multicolumn{1}{c}{\thead{Baseline}}&
	\multicolumn{3}{c}{\thead{{+ School}\\{Policies}}}&
	\multicolumn{1}{c}{\thead{{+ Private}\\{School}}}&
	\multicolumn{2}{c}{\thead{{+ Teacher}\\{Composition}}}&
	\multicolumn{1}{c}{\thead{{+ School}\\{FE}}}\\;
tex \cmidrule(lr){2-2}\cmidrule(lr){3-5}\cmidrule(lr){6-6}\cmidrule(lr){7-8}\cmidrule(lr){9-9}\\;
tex \thead[l]{{~}\\{Outcome:}\\{Years of Education}}&
			 \thead{{~}\\{~}\\{(1)}}&
			 \thead{{Retention}\\{Policy}\\{(2)}}&
			 \thead{{Ability}\\{Groups}\\{(3)}}&
 			 \thead{{Strict.}\\{Index}\\{(4)}}&
 			 \thead{{~}\\{~}\\{(5)}}&
			 \thead{{White}\\{Teacher}\\{(6)}}&
			 \thead{{Female}\\{Teacher}\\{(7)}}&
			 \thead{{~}\\{~}\\{(8)}}\\;
tex \midrule;
tex \thead[l]{\PGS}										&${c_1_1}&${c_2_1}&${c_3_1}&${c_4_1}&${c_5_1}&${c_6_1}&${c_7_1}&${c_8_1}\\;
tex \thead[l]{\IQuali}									&${c_1_2}&${c_2_2}&${c_3_2}&${c_4_2}&${c_5_2}&${c_6_2}&${c_7_2}&${c_8_2}\\;
tex \thead[l]{\PGS $\times$ \IQuali} 					&${c_1_3}&${c_2_3}&${c_3_3}&${c_4_3}&${c_5_3}&${c_6_3}&${c_7_3}&${c_8_3}\\;
tex \thead[l]{School Characteristic}					&${c_1_4}&${c_2_4}&${c_3_4}&${c_4_4}&${c_5_4}&${c_6_4}&${c_7_4}&${c_8_4}\\;
tex \thead[l]{{\PGS $\times$}\\{School Characteristic}}	&${c_1_5}&${c_2_5}&${c_3_5}&${c_4_5}&${c_5_5}&${c_6_5}&${c_7_5}&${c_8_5}\\;
tex \midrule;
tex \thead[l]{Child Controls}	&\ye&\ye&\ye&\ye&\ye&\ye&\ye&\ye\\;
tex \thead[l]{Family Controls}	&\ye&\ye&\ye&\ye&\ye&\ye&\ye&\ye\\;
tex \thead[l]{Control Function}	&\ye&\ye&\ye&\ye&\ye&\ye&\ye&\ye\\;
tex \thead[l]{N}				&$ob_1&$ob_2&$ob_3&$ob_4&$ob_5&$ob_6&$ob_7&$ob_8\\;
tex \thead[l]{$\text{R}^2$}		&$rs_1&$rs_2&$rs_3&$rs_4&$rs_5&$rs_6&$rs_7&$rs_8\\;
tex \bottomrule;
tex \end{tabular*};
#delimit cr
texdoc close

local title "Robustness to Additional School Characteristics"
local desc  "This table shows the joint association of \PGS and \IQuali" ///
			"with completed years of education." ///
			"We control for additional school characteristics and their interaction with" ///
			"\PGS\negspace. The relevant school characteristics are indicated in the column header."
#delimit;
textab, title(`title') name(`name') replace
width(1.3) file(tex) notesize(`notesize')
note_paper("`source' `desc' `controls' `controlfct' `standard' `signif' `error'")
data(`data')
inpath(${tablepath}) path_paper(${paper_tables});
#delimit cr

// -----------------------------------------------------
// Table 6
// -----------------------------------------------------
use "${data}data_estim.dta", replace
local name tab6

/*Get Estimates*/
local models t6_1 t6_2 t6_3 t6_4
local coefs pgs_edu ///
f_over1 ///
c.pgs_edu#c.f_over1 ///
inv auth2 ///
c.inv#c.pgs_edu c.auth2#c.pgs_edu ///
c.inv#c.f_over1 c.auth2#c.f_over1
output `models', clist(`coefs') replay

/*Set up Table*/
cap texdoc init "${tablepath}`name'.tex", replace force
#delimit;
tex \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi};
tex \begin{tabular*}{1\linewidth}{@{\hskip\tabcolsep\extracolsep\fill}l*{4}{c}};
tex \toprule;
tex \multicolumn{1}{c}{\textbf{~}}&
	\multicolumn{2}{c}{\thead[c]{Parental Investment}}&
	\multicolumn{2}{c}{\thead[c]{Parenting Style}}\\;
tex \cmidrule(lr){2-3}\cmidrule(lr){4-5};
tex \thead[l]{}
			 &\thead{{(1)}}
			 &\thead{{(2)}}
			 &\thead{{(3)}}
			 &\thead{{(4)}}\\;
tex \midrule;
tex \thead[l]{\PGS}						  			&${c_1_1}&${c_2_1}&${c_3_1}&${c_4_1} \\;
tex \thead[l]{\IQuali}					  			&${c_1_2}&${c_2_2}&${c_3_2}&${c_4_2} \\;
tex \thead[l]{\PGS $\times$ \IQuali}	  			&${c_1_3}&${c_2_3}&${c_3_3}&${c_4_3} \\;
tex \midrule;
tex \thead[l]{Child Controls}			&\ye&\ye&\ye&\ye\\;
tex \thead[l]{Family Controls}			&\ye&\ye&\ye&\ye\\;
tex \thead[l]{Control Function}			&\ye&\ye&\ye&\ye\\;
tex \thead[l]{Sibling \PGS}				&\no&\ye&\no&\ye\\;
tex \thead[l]{N}						&$ob_1&$ob_2&$ob_3&$ob_4\\;
tex \thead[l]{$\text{R}^2$}				&$rs_1&$rs_2&$rs_3&$rs_4\\;
tex \thead[l]{Outcome Mean}				&$mu_1&$mu_2&$mu_3&$mu_4\\;
tex \thead[l]{Outcome SD}				&$sd_1&$sd_2&$sd_3&$sd_4\\;
tex \bottomrule;
tex \end{tabular*};
#delimit cr
texdoc close

local title "Association of Parental Investments and Parenting Styles with \PGS and \IQuali"
local desc  "This table shows the joint association of \PGS and \IQuali" ///
			"with indexes of parental time investments."
#delimit;
textab, title(`title') name(`name') replace
width(1.3) file(tex) notesize(`notesize')
note_paper("`source' `desc' `controls' `controlfct' `standard' `signif' `error'")
data(`data')
inpath(${tablepath}) path_paper(${paper_tables});
#delimit cr

// -----------------------------------------------------
// Table 7
// -----------------------------------------------------
use "${data}data_estim.dta", replace
local name tab7

/*Get Estimates*/
local models ///
t7_1 t7_2 t7_3 t7_4 t7_5 t7_6 t7_7 t7_8 t7_9 t7_10
local coefs ///
pgs_edu f_over1 c.pgs_edu#c.f_over1

output `models', clist(`coefs') replay

/*Set up Table*/
texdoc init "${tablepath}`name'.tex", replace force
#delimit;
tex \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi};
tex \begin{tabular*}{1\linewidth}{@{\hskip\tabcolsep\extracolsep\fill}l*{8}{c}};
tex \toprule;
tex \multicolumn{1}{c}{~}&\multicolumn{1}{c}{\thead{Cognitive}}&\multicolumn{2}{c}{\thead{Preferences}}&\multicolumn{2}{c}{\thead{Health}}\\;
tex \cmidrule(lr){2-2}\cmidrule(lr){3-4}\cmidrule(lr){5-6};
tex \thead[l]{{\emph{Panel (a)}}\\{~}\\{~}}&
	\thead{{PVT}\\{(1)}}&
 	\thead{{Risk}\\{(2)}}&
 	\thead{{Patience}\\{(3)}}&
 	\thead{{Subjective}\\{(4)}}&
 	\thead{{Objective}\\{(5)}}\\;
tex \midrule;
tex \thead[l]{\PGS}						&${c_1_1}&${c_2_1}&${c_3_1}&${c_4_1}&${c_5_1}\\;
tex \thead[l]{\IQuali}					&${c_1_2}&${c_2_2}&${c_3_2}&${c_4_2}&${c_5_2}\\;
tex \thead[l]{\PGS $\times$ \IQuali}	&${c_1_3}&${c_2_3}&${c_3_3}&${c_4_3}&${c_5_3}\\;
tex \midrule \thead[l]{Child Controls}	&\ye&\ye&\ye&\ye&\ye\\;
tex \thead[l]{Family Controls}			&\ye&\ye&\ye&\ye&\ye\\;
tex \thead[l]{Control Function}			&\ye&\ye&\ye&\ye&\ye\\;
tex \thead[l]{N}						&$ob_1&$ob_2&$ob_3&$ob_4&$ob_5\\;
tex \thead[l]{$\text{R}^2$}				&$rs_1&$rs_2&$rs_3&$rs_4&$rs_5\\;
tex \midrule;
tex \multicolumn{1}{c}{~}&\multicolumn{5}{c}{\thead{Personality}}\\;
tex \cmidrule(lr){2-6};
tex \thead[l]{{\emph{Panel (b)}}\\{~}\\{~}}&
 	\thead{{Open-}\\{ness}\\{(1)}}&
 	\thead{{Conscient-}\\{iousness}\\{(2)}}&
 	\thead{{Extra-}\\{version}\\{(3)}}&
 	\thead{{Agree-}\\{ableness}\\{(4)}}&
 	\thead{{Neuro-}\\{ticism}\\{(5)}}\\;
tex \midrule;
tex \thead[l]{\PGS}						&${c_6_1}&${c_7_1}&${c_8_1}&${c_9_1}&${c_10_1}\\;
tex \thead[l]{\IQuali}					&${c_6_2}&${c_7_2}&${c_8_2}&${c_9_2}&${c_10_2}\\;
tex \thead[l]{\PGS $\times$ \IQuali}	&${c_6_3}&${c_7_3}&${c_8_3}&${c_9_3}&${c_10_3}\\;
tex \midrule \thead[l]{Child Controls}	&\ye&\ye&\ye&\ye&\ye\\;
tex \thead[l]{Family Controls}			&\ye&\ye&\ye&\ye&\ye\\;
tex \thead[l]{Control Function}			&\ye&\ye&\ye&\ye&\ye\\;
tex \thead[l]{N}						&$ob_6&$ob_7&$ob_8&$ob_9&$ob_10\\;
tex \thead[l]{$\text{R}^2$}				&$rs_6&$rs_7&$rs_8&$rs_9&$rs_10\\;
tex \bottomrule;
tex \end{tabular*};
#delimit cr
texdoc close

local title "Association of Skill Measures with \PGS by \IQuali"
local desc 	"This table shows the joint association of \PGS and \IQuali" ///
			"with cognitive skills, preferences, health, and personality."
#delimit;
textab, title(`title') name(`name') replace ///
width(1.3) file(tex) notesize(`notesize')
note_paper("`source' `desc' `controls' `controlfct' `standard' `signif' `error'")
data(`data')
inpath(${tablepath}) path_paper(${paper_tables});
#delimit cr

